import unittest

from api.ihrm_dept_crud_api import IhrmDeptCRUDApi
from api.ihrm_login_api import IhrmLoginApi
from uilts.common_asserts import comm_asserts
from uilts.get_token import get_login_token


class TestDeptCRUD(unittest.TestCase):
    token = None

    @classmethod
    def setUpClass(cls):
        if cls.token is None:
            cls.token = get_login_token()

    @classmethod
    def tearDownClass(cls):
        if cls.token is not None:
            cls.token = None

    def test_add_emp(self):
        emp_data = {
            "name": "总裁部a",
            "code": "ZCBa"
        }
        resp = IhrmDeptCRUDApi.add_dept_api(emp_data, self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_query_emp(self):
        resp = IhrmDeptCRUDApi.query_dept_api("1175311418004013056", self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_modify_emp(self):
        emp_data = {"name": "jackie", "code": "asd"}
        resp = IhrmDeptCRUDApi.modify_dept_api("1913179775611351040", emp_data, self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")

    def test_delete_emp(self):
        resp = IhrmDeptCRUDApi.delete_dept_api("1913183671205408768", self.token)
        comm_asserts(self, resp, 200, True, 10000, "操作成功")
